package com.lan.iot.fragment;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lan.iot.ListAdapterm;
import com.lan.iot.MainActivity;
import com.lan.iot.R;
import com.lan.iot.RecyAdapter;

import java.util.ArrayList;
import java.util.List;


public class VPFragmentm extends Fragment {

    private static final String ARG_PARAM1 = "title";
    private static final String ARG_PARAM2 = "img";

    private String title;
    private int img;
    private static List<String> settings = new ArrayList<>();
    {
//        settings.add("设置");
        settings.add("设置");
        settings.add("修改密码");
        settings.add("退出登录");
    }

    public static VPFragmentm newInstance(String title, int img) {
        VPFragmentm fragment = new VPFragmentm();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, title);
        args.putInt(ARG_PARAM2, img);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            title = getArguments().getString(ARG_PARAM1);
            img = getArguments().getInt(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_me, container, false);
        List<String> setting = new ArrayList<>();
        for(int i=0;i<3;i++){
            setting.add(settings.get(i));
        }
        ListAdapterm adapter = new ListAdapterm(getContext(), R.layout.item_, setting);
        ListView listView = view.findViewById(R.id.lv);
        //将适配器中数据添加到ListView中
        listView.setAdapter(adapter);

//        RecyAdapter mAdapter;
//        RecyclerView mRecyclerView;
//        mRecyclerView=view.findViewById(R.id.recycler_view);
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2, LinearLayoutManager.VERTICAL,false);
//
//        mRecyclerView.setLayoutManager(gridLayoutManager);
//        mAdapter = new RecyAdapter(getContext());
//        mRecyclerView.setAdapter(mAdapter);
//
//        /**
//         * 设置网格布局每个item的间距
//         */
//        mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
//            @Override
//            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
//                super.getItemOffsets(outRect, view, parent, state);
//                //item1距离底部的距离
//                outRect.bottom = 30;
//                //item距离左侧的距离
//                outRect.left = 30;
//            }
//        });

//        ImageView iv = view.findViewById(R.id.iv);
//        iv.setImageResource(argument.getInt(ARG_PARAM2,R.drawable.ji1));
        return view;
    }
}